<?php

namespace App\Http\Middleware;

use Closure;
use InfyOm\Generator\Utils\ResponseUtil;
use Response;

class WechatMiniApp
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $auth = $request->header('Authorization');

        if ( $auth != md5(config('custom.wechat_miniapp_sk')) ) {
            return Response::json(ResponseUtil::makeError("Invalid Token"), 403);
        }

        return $next($request);
    }
}
